#Boa:Frame:BlackBird

import wx, os, sys, ConfigParser
from GlobalOptionDialog import *
from FileEsclusiDialog import *

#DIR = '/home/emanuele/Progetti/BoaProgetti/BlackBirdDaemon'
DIR = 'D:\Documents and Settings\A127027\Documenti\\tmp\BlackBirdDaemon'
FILE = 'config.cfg'


def create(parent):
    return BlackBird(parent)

[wxID_BLACKBIRD, wxID_BLACKBIRDAUTOMATICORADIOBUTTON, 
 wxID_BLACKBIRDDESTINAZIONETEXT, wxID_BLACKBIRDELIMINABUTTON, 
 wxID_BLACKBIRDESCIBUTTON, wxID_BLACKBIRDFILEESCLUSIBUTTON, 
 wxID_BLACKBIRDFLAGCOMPLETI, wxID_BLACKBIRDFLAGCOMPRESSO, 
 wxID_BLACKBIRDFLAGDATAORA, wxID_BLACKBIRDFLAGHARDLINK, 
 wxID_BLACKBIRDFLAGMANTIENIPROPIETARIO, wxID_BLACKBIRDFLAGPERMESSI, 
 wxID_BLACKBIRDFLAGRICORSIVO, wxID_BLACKBIRDFLAGSOSPESO, 
 wxID_BLACKBIRDGRAFICVIEW, wxID_BLACKBIRDMIRRORRADIOBUTTON, 
 wxID_BLACKBIRDMODIFICABUTTON, wxID_BLACKBIRDNOMETEXT, wxID_BLACKBIRDNOTETEXT, 
 wxID_BLACKBIRDNUOVOBUTTON, wxID_BLACKBIRDPREFENZEBUTTON, 
 wxID_BLACKBIRDRIPRISTINABACKUPBUTTON, wxID_BLACKBIRDSALVABUTTON, 
 wxID_BLACKBIRDSASHWINDOW1, wxID_BLACKBIRDSASHWINDOW2, 
 wxID_BLACKBIRDSASHWINDOW3, wxID_BLACKBIRDSORGENTEBROSWER, 
 wxID_BLACKBIRDSORGENTETEXT, wxID_BLACKBIRDSTATICBOX1, 
 wxID_BLACKBIRDSTATICBOX2, wxID_BLACKBIRDSTATICTEXT1, 
 wxID_BLACKBIRDSTATICTEXT2, wxID_BLACKBIRDSTATICTEXT3, 
 wxID_BLACKBIRDSTATICTEXT4, wxID_BLACKBIRDUPDATERADIOBUTTON, 
] = [wx.NewId() for _init_ctrls in range(35)]

class BlackBird(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_BLACKBIRD, name='BlackBird',
              parent=prnt, pos=wx.Point(342, 262), size=wx.Size(716, 480),
              style=wx.DEFAULT_FRAME_STYLE, title='Black Bird Config Tools')
        self.SetClientSize(wx.Size(708, 447))
        self.Enable(True)

        self.sashWindow1 = wx.SashWindow(id=wxID_BLACKBIRDSASHWINDOW1,
              name='sashWindow1', parent=self, pos=wx.Point(328, 0),
              size=wx.Size(376, 400), style=wx.CLIP_CHILDREN | wx.SW_3D)

        self.staticText1 = wx.StaticText(id=wxID_BLACKBIRDSTATICTEXT1,
              label='Nome', name='staticText1', parent=self.sashWindow1,
              pos=wx.Point(8, 16), size=wx.Size(88, 13), style=0)

        self.NomeText = wx.TextCtrl(id=wxID_BLACKBIRDNOMETEXT, name='NomeText',
              parent=self.sashWindow1, pos=wx.Point(112, 8), size=wx.Size(256,
              21), style=wx.TE_READONLY, value='')

        self.staticText2 = wx.StaticText(id=wxID_BLACKBIRDSTATICTEXT2,
              label=u'Sorgente', name='staticText2', parent=self.sashWindow1,
              pos=wx.Point(8, 40), size=wx.Size(84, 17), style=0)

        self.SorgenteText = wx.TextCtrl(id=wxID_BLACKBIRDSORGENTETEXT,
              name='SorgenteText', parent=self.sashWindow1, pos=wx.Point(112,
              32), size=wx.Size(232, 21), style=wx.TE_READONLY, value='')

        self.SorgenteBroswer = wx.Button(id=wxID_BLACKBIRDSORGENTEBROSWER,
              label='...', name='SorgenteBroswer', parent=self.sashWindow1,
              pos=wx.Point(344, 32), size=wx.Size(24, 23), style=0)
        self.SorgenteBroswer.Enable(False)
        self.SorgenteBroswer.Bind(wx.EVT_BUTTON, self.OnSorgenteBroswerButton,
              id=wxID_BLACKBIRDSORGENTEBROSWER)

        self.staticText3 = wx.StaticText(id=wxID_BLACKBIRDSTATICTEXT3,
              label=u'Destinazione', name='staticText3',
              parent=self.sashWindow1, pos=wx.Point(8, 64), size=wx.Size(101,
              17), style=0)

        self.DestinazioneText = wx.TextCtrl(id=wxID_BLACKBIRDDESTINAZIONETEXT,
              name='DestinazioneText', parent=self.sashWindow1,
              pos=wx.Point(112, 56), size=wx.Size(256, 21),
              style=wx.TE_READONLY, value='')

        self.staticText4 = wx.StaticText(id=wxID_BLACKBIRDSTATICTEXT4,
              label='Note', name='staticText4', parent=self.sashWindow1,
              pos=wx.Point(8, 88), size=wx.Size(104, 13), style=0)

        self.NoteText = wx.TextCtrl(id=wxID_BLACKBIRDNOTETEXT, name='NoteText',
              parent=self.sashWindow1, pos=wx.Point(112, 80), size=wx.Size(256,
              112), style=wx.TE_READONLY | wx.TE_MULTILINE, value='')

        self.staticBox1 = wx.StaticBox(id=wxID_BLACKBIRDSTATICBOX1,
              label="Modalita'", name='staticBox1', parent=self.sashWindow1,
              pos=wx.Point(8, 192), size=wx.Size(264, 56), style=0)

        self.MirrorRadioButton = wx.RadioButton(id=wxID_BLACKBIRDMIRRORRADIOBUTTON,
              label='Mirror', name='MirrorRadioButton', parent=self.sashWindow1,
              pos=wx.Point(16, 208), size=wx.Size(72, 32), style=0)
        self.MirrorRadioButton.SetValue(True)
        self.MirrorRadioButton.Enable(False)
        self.MirrorRadioButton.Bind(wx.EVT_RADIOBUTTON,
              self.OnMirrorRadioButtonRadiobutton,
              id=wxID_BLACKBIRDMIRRORRADIOBUTTON)

        self.UpDateRadioButton = wx.RadioButton(id=wxID_BLACKBIRDUPDATERADIOBUTTON,
              label='Update', name='UpDateRadioButton', parent=self.sashWindow1,
              pos=wx.Point(96, 208), size=wx.Size(64, 32), style=0)
        self.UpDateRadioButton.SetValue(True)
        self.UpDateRadioButton.Enable(False)
        self.UpDateRadioButton.Bind(wx.EVT_RADIOBUTTON,
              self.OnUpDateRadioButtonRadiobutton,
              id=wxID_BLACKBIRDUPDATERADIOBUTTON)

        self.staticBox2 = wx.StaticBox(id=wxID_BLACKBIRDSTATICBOX2,
              label='Opzioni', name='staticBox2', parent=self.sashWindow1,
              pos=wx.Point(8, 248), size=wx.Size(360, 144), style=0)

        self.FlagPermessi = wx.CheckBox(id=wxID_BLACKBIRDFLAGPERMESSI,
              label='Mantieni permessi', name='FlagPermessi',
              parent=self.sashWindow1, pos=wx.Point(24, 328), size=wx.Size(120,
              24), style=0)
        self.FlagPermessi.SetValue(False)
        self.FlagPermessi.Enable(False)
        self.FlagPermessi.SetToolTipString('Replica fedelmente i permessi')

        self.FlagHardLink = wx.CheckBox(id=wxID_BLACKBIRDFLAGHARDLINK,
              label='Mantieni hard link', name='FlagHardLink',
              parent=self.sashWindow1, pos=wx.Point(24, 296), size=wx.Size(176,
              24), style=0)
        self.FlagHardLink.SetValue(False)
        self.FlagHardLink.Enable(False)
        self.FlagHardLink.SetToolTipString('Mantiene i riferimenti dei link')

        self.FlagSospeso = wx.CheckBox(id=wxID_BLACKBIRDFLAGSOSPESO,
              label='Sospeso', name='FlagSospeso', parent=self.sashWindow1,
              pos=wx.Point(24, 264), size=wx.Size(128, 24), style=0)
        self.FlagSospeso.SetValue(False)
        self.FlagSospeso.Enable(False)
        self.FlagSospeso.SetToolTipString('Sospende il profilo di backup')

        self.FlagCompresso = wx.CheckBox(id=wxID_BLACKBIRDFLAGCOMPRESSO,
              label='Compresso', name='FlagCompresso', parent=self.sashWindow1,
              pos=wx.Point(208, 264), size=wx.Size(112, 24), style=0)
        self.FlagCompresso.SetValue(False)
        self.FlagCompresso.Enable(False)
        self.FlagCompresso.SetToolTipString('Comprime i file prima di trasferirli')

        self.FlagMantieniPropietario = wx.CheckBox(id=wxID_BLACKBIRDFLAGMANTIENIPROPIETARIO,
              label='Mantieni propietario', name='FlagMantieniPropietario',
              parent=self.sashWindow1, pos=wx.Point(208, 296), size=wx.Size(152,
              24), style=0)
        self.FlagMantieniPropietario.SetValue(False)
        self.FlagMantieniPropietario.Enable(False)
        self.FlagMantieniPropietario.SetToolTipString('Replica fedelmente il proprietario del file originale')
        self.FlagMantieniPropietario.Bind(wx.EVT_CHECKBOX,
              self.OnFlagMantieniPropietarioCheckbox,
              id=wxID_BLACKBIRDFLAGMANTIENIPROPIETARIO)

        self.sashWindow2 = wx.SashWindow(id=wxID_BLACKBIRDSASHWINDOW2,
              name='sashWindow2', parent=self, pos=wx.Point(0, 0),
              size=wx.Size(328, 400), style=wx.CLIP_CHILDREN | wx.SW_3D)

        self.GraficView = wx.ListCtrl(id=wxID_BLACKBIRDGRAFICVIEW,
              name=u'GraficView', parent=self.sashWindow2, pos=wx.Point(0, 0),
              size=wx.Size(328, 400), style=wx.LC_LIST)
        self.GraficView.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
              self.OnGraficViewListItemActivated, id=wxID_BLACKBIRDGRAFICVIEW)

        self.sashWindow3 = wx.SashWindow(id=wxID_BLACKBIRDSASHWINDOW3,
              name='sashWindow3', parent=self, pos=wx.Point(0, 400),
              size=wx.Size(704, 44), style=wx.CLIP_CHILDREN | wx.SW_3D)

        self.SalvaButton = wx.Button(id=wxID_BLACKBIRDSALVABUTTON,
              label='Salva', name='SalvaButton', parent=self.sashWindow3,
              pos=wx.Point(512, 8), size=wx.Size(80, 32), style=0)
        self.SalvaButton.SetToolTipString('Salva le modifiche')
        self.SalvaButton.Bind(wx.EVT_BUTTON, self.OnSalvaButtonButton,
              id=wxID_BLACKBIRDSALVABUTTON)

        self.NuovoButton = wx.Button(id=wxID_BLACKBIRDNUOVOBUTTON,
              label=u'Nuovo', name=u'NuovoButton', parent=self.sashWindow3,
              pos=wx.Point(216, 8), size=wx.Size(85, 32), style=0)
        self.NuovoButton.SetToolTipString('Crea un nuovo profilo di backup')
        self.NuovoButton.Bind(wx.EVT_BUTTON, self.OnNuovoButtonButton,
              id=wxID_BLACKBIRDNUOVOBUTTON)

        self.EsciButton = wx.Button(id=wxID_BLACKBIRDESCIBUTTON, label='Esci',
              name='EsciButton', parent=self.sashWindow3, pos=wx.Point(608, 8),
              size=wx.Size(80, 32), style=0)
        self.EsciButton.SetToolTipString("Esce dall'applicazione")
        self.EsciButton.Bind(wx.EVT_BUTTON, self.OnEsciButtonButton,
              id=wxID_BLACKBIRDESCIBUTTON)

        self.ModificaButton = wx.Button(id=wxID_BLACKBIRDMODIFICABUTTON,
              label=u'Modifica', name=u'ModificaButton',
              parent=self.sashWindow3, pos=wx.Point(320, 8), size=wx.Size(85,
              32), style=0)
        self.ModificaButton.SetToolTipString('Modifica un profilo')
        self.ModificaButton.Bind(wx.EVT_BUTTON, self.OnModificaButtonButton,
              id=wxID_BLACKBIRDMODIFICABUTTON)

        self.PrefenzeButton = wx.Button(id=wxID_BLACKBIRDPREFENZEBUTTON,
              label='Preferenze', name='PrefenzeButton',
              parent=self.sashWindow3, pos=wx.Point(120, 8), size=wx.Size(80,
              32), style=0)
        self.PrefenzeButton.SetToolTipString('Configura il daemon di connssione')
        self.PrefenzeButton.Bind(wx.EVT_BUTTON, self.OnPrefenzeButtonButton,
              id=wxID_BLACKBIRDPREFENZEBUTTON)

        self.EliminaButton = wx.Button(id=wxID_BLACKBIRDELIMINABUTTON,
              label='Elimina', name='EliminaButton', parent=self.sashWindow3,
              pos=wx.Point(424, 8), size=wx.Size(75, 32), style=0)
        self.EliminaButton.SetToolTipString('Elimina un profilo')
        self.EliminaButton.Bind(wx.EVT_BUTTON, self.OnEliminaButtonButton,
              id=wxID_BLACKBIRDELIMINABUTTON)

        self.FlagDataOra = wx.CheckBox(id=wxID_BLACKBIRDFLAGDATAORA,
              label='Mantieni data e ora', name='FlagDataOra',
              parent=self.sashWindow1, pos=wx.Point(208, 328), size=wx.Size(152,
              21), style=0)
        self.FlagDataOra.SetValue(False)
        self.FlagDataOra.Enable(False)
        self.FlagDataOra.SetToolTipString("Replica fedelmente la data e l'ora dell'originale")

        self.FileEsclusiButton = wx.Button(id=wxID_BLACKBIRDFILEESCLUSIBUTTON,
              label='File Escusi', name='FileEsclusiButton',
              parent=self.sashWindow1, pos=wx.Point(280, 208), size=wx.Size(80,
              31), style=0)
        self.FileEsclusiButton.Enable(False)
        self.FileEsclusiButton.SetToolTipString('Elenca i file da escludere dal profilo')
        self.FileEsclusiButton.Bind(wx.EVT_BUTTON,
              self.OnFileEsclusiButtonButton,
              id=wxID_BLACKBIRDFILEESCLUSIBUTTON)

        self.AutomaticoRadiobutton = wx.RadioButton(id=wxID_BLACKBIRDAUTOMATICORADIOBUTTON,
              label='Automatico', name='AutomaticoRadiobutton',
              parent=self.sashWindow1, pos=wx.Point(184, 216), size=wx.Size(81,
              13), style=0)
        self.AutomaticoRadiobutton.SetValue(False)
        self.AutomaticoRadiobutton.Enable(False)
        self.AutomaticoRadiobutton.Bind(wx.EVT_RADIOBUTTON,
              self.OnAutomaticoRadiobuttonRadiobutton,
              id=wxID_BLACKBIRDAUTOMATICORADIOBUTTON)

        self.FlagRicorsivo = wx.CheckBox(id=wxID_BLACKBIRDFLAGRICORSIVO,
              label='Ricorsivo', name='FlagRicorsivo', parent=self.sashWindow1,
              pos=wx.Point(24, 360), size=wx.Size(136, 21), style=0)
        self.FlagRicorsivo.SetValue(False)
        self.FlagRicorsivo.Enable(False)
        self.FlagRicorsivo.SetToolTipString("Backup ricorsivo all'interno della cartella")

        self.FlagCompleti = wx.CheckBox(id=wxID_BLACKBIRDFLAGCOMPLETI,
              label='File completi', name='FlagCompleti',
              parent=self.sashWindow1, pos=wx.Point(208, 360), size=wx.Size(136,
              21), style=0)
        self.FlagCompleti.SetValue(False)
        self.FlagCompleti.Enable(False)
        self.FlagCompleti.SetToolTipString("Forza il trasferimento dell'intero file")

        self.RipristinaBackupButton = wx.Button(id=wxID_BLACKBIRDRIPRISTINABACKUPBUTTON,
              label='Ripristina', name='RipristinaBackupButton',
              parent=self.sashWindow3, pos=wx.Point(16, 8), size=wx.Size(88,
              31), style=0)
        self.RipristinaBackupButton.SetToolTipString('Rispristina backup selezionato')
        self.RipristinaBackupButton.Bind(wx.EVT_BUTTON,
              self.OnRipristinaBackupButtonButton,
              id=wxID_BLACKBIRDRIPRISTINABACKUPBUTTON)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.Sorgenti = {}
        self.Destinazioni = {}
        self.Opzioni  = {}
        self.Note = {}
        self.Sospesi = {}
        self.Client = {}
        self.FileEsclusi = {}
        self.index = 0
        self.Selected = 0
        self.item = ''
        self.indexRemoved = []
        config = ConfigParser.ConfigParser()
    	fd = open(os.path.join(DIR, FILE), 'r')
    	config.readfp(fd)
        ListaSorgenti = config.items('Local')
        ListaDestinazione = config.items('Remote')
        ListaOpzioni = config.items('Opzioni')
        ListaNote = config.items('Note')
        ListaSospesi = config.items('Sospesi')
        ListaClient = config.items('Client')
        ListaFileEsclusi = config.items('FileEsclusi')
        
    	fd.close()
        self.SalvaButton.Enable(False)
    	for item in ListaSorgenti:
    	    self.Sorgenti[item[0]] = item[1]
        for item in ListaDestinazione:
    	    self.Destinazioni[item[0]] = item[1]
        for item in ListaOpzioni:
    	    self.Opzioni[item[0]] = item[1]
        for item in ListaNote:
    	    self.Note[item[0]] = item[1]
        for item in ListaSospesi:
    	    self.Sospesi[item[0]] = item[1]
        for item in ListaClient:
    	    self.Client[item[0]] = item[1]
        for item in ListaFileEsclusi:
            self.FileEsclusi[item[0]] = item[1]
    	    
        self.SorgentiKeys = self.Sorgenti.keys()
        self.index = 0
        for key in self.SorgentiKeys:
            self.GraficView.InsertStringItem(self.index,key)
            self.index +=1
        

    def OnEsciButtonButton(self, event):
        config = ConfigParser.ConfigParser()
    	config.read(os.path.join(DIR, FILE))
    	
        for key in self.Sorgenti.keys():
            config.set('Local', key, self.Sorgenti[key])
        for key in self.Destinazioni.keys():
            config.set('Remote', key, self.Destinazioni[key])
        for key in self.Opzioni.keys():
            config.set('Opzioni', key, self.Opzioni[key])
        for key in self.Note.keys():
            config.set('Note', key, self.Note[key])
        for key in self.Sospesi.keys():
            config.set('Sospesi', key, self.Sospesi[key])
        for key in self.Client.keys():
            config.set('Client', key, self.Client[key])
        for key in self.FileEsclusi.keys():
            config.set('FileEsclusi', key, self.FileEsclusi[key])
        
        for item in self.indexRemoved:
            config.remove_option('Local', item)
            config.remove_option('Remote', item)
            config.remove_option('Opzioni', item)
            config.remove_option('Note', item)
            config.remove_option('Sospesi', item)
            config.remove_option('FileEsclusi', item)
    	try:
            fd = open(os.path.join(DIR, FILE), 'w')
            config.write(fd)
            fd.close()
        except IOError:
            print 'errore scrittura file'
            
        sys.exit()

    def OnRadioButton1Radiobutton(self, event):
        event.Skip()

    def OnSorgenteBroswerButton(self, event):
        dlg = wx.DirDialog(self)
        try:
            if dlg.ShowModal() == wx.ID_OK:
                path = dlg.GetPath()
                self.SorgenteText.SetValue(path)
        finally:
            dlg.Destroy()

    def OnOpzioniButtonButton(self, event):
        event.Skip()

    def OnSalvaButtonButton(self, event):
        self.NomeText.SetEditable(False)
        self.SorgenteText.SetEditable(False)
        self.DestinazioneText.SetEditable(False)
        self.NoteText.SetEditable(False)
        self.SorgenteBroswer.Enable(False)
        self.FlagCompresso.Enable(False)
        self.FlagDataOra.Enable(False)
        self.FlagHardLink.Enable(False)
        self.FlagMantieniPropietario.Enable(False)
        self.FlagPermessi.Enable(False)
        self.FlagSospeso.Enable(False)
        self.FileEsclusiButton.Enable(False)
        self.MirrorRadioButton.Enable(False)
        self.UpDateRadioButton.Enable(False)
        self.FlagRicorsivo.Enable(False)
        self.FlagCompleti.Enable(False)
        self.AutomaticoRadiobutton.Enable(False)
        self.FileEsclusiButton.Enable(False)
        
        nome = str(self.NomeText.GetValue())
        sorgente = str(self.SorgenteText.GetValue())
        destinazione = str(self.DestinazioneText.GetValue())
        note = str(self.NoteText.GetValue())
        self.Sorgenti[nome] = sorgente
        self.Destinazioni[nome] = destinazione
        self.Note[nome] = note
        if self.FlagSospeso.IsChecked():
            self.Sospesi[nome] = True
        else:
            self.Sospesi[nome] = False
        
        opzioni = ''
        if self.AutomaticoRadiobutton.GetValue() == True:
            opzioni +='a'
        else:
            if self.FlagPermessi.IsChecked():
                opzioni += 'p' 
            if self.FlagCompresso.IsChecked():
                opzioni += 'z'
            if self.FlagHardLink.IsChecked():
                opzioni += 'H'
            if self.FlagDataOra.IsChecked():
                opzioni += 't'
            if self.FlagMantieniPropietario.IsChecked():
                opzioni += 'o'
            if self.FlagRicorsivo.IsChecked():
                opzioni += 'r'
            if self.FlagCompleti.IsChecked():
                opzioni += 'W'
            if self.UpDateRadioButton.GetValue() == True:
                opzioni += 'u'
        
            
        self.Opzioni[nome] = opzioni
        self.NuovoButton.Enable(True)
        self.SalvaButton.Enable(False)
        

        

    def OnGraficViewListItemActivated(self, event):
        self.Selected = event.GetIndex()
        self.item = event.GetText()
        self.NomeText.SetValue(self.item)
        self.SorgenteText.SetValue(self.Sorgenti[self.item])
        self.DestinazioneText.SetValue(self.Destinazioni[self.item])
        self.NoteText.SetValue(self.Note[self.item])
        if self.Sospesi[self.item] == 'True':
            self.FlagSospeso.SetValue(True)
        else:
            self.FlagSospeso.SetValue(False)
            
        self.FlagPermessi.SetValue(False)
        self.FlagCompresso.SetValue(False)
        self.FlagMantieniPropietario.SetValue(False)
        self.FlagDataOra.SetValue(False)
        self.FlagHardLink.SetValue(False)
        self.UpDateRadioButton.SetValue(False)
        self.FlagRicorsivo.Enable(False)
        self.FlagCompleti.Enable(False)
        self.MirrorRadioButton.SetValue(True)
        
        for i in self.Opzioni[self.item]:
            if i == 'a':
                self.AutomaticoRadiobutton.SetValue(True)
            else:
                if i == 'p':
                    self.FlagPermessi.SetValue(True)
                elif i == 'z':
                    self.FlagCompresso.SetValue(True)
                elif i == 'o':
                    self.FlagMantieniPropietario.SetValue(True)
                elif i == 't':
                    self.FlagDataOra.SetValue(True)
                elif i == 'H':
                    self.FlagHardLink.SetValue(True)
                elif i == 'u':
                    self.UpDateRadioButton.SetValue(True)
                elif i == 'r':
                    self.FlagRicorsivo.SetValue(True)
                elif i == 'W':
                    self.FlagCompleti.SetValue(True)
            

    def OnNuovoButtonButton(self, event):
        self.NuovoButton.Enable(False)
        dlg = wx.TextEntryDialog(self, 'Nome nuovo elemento di backup', 'Nuovo Oggetto', 'Default')
        try:
            if dlg.ShowModal() == wx.ID_OK:
                result = dlg.GetValue()
                for key in self.Sorgenti.keys():
                    if str(result) == key:
                        dlg = wx.MessageDialog(self, "Esiste gia' un oggetto con questo nome", 'Attenzione', wx.OK | wx.ICON_ERROR)
                        try:
                            result = dlg.ShowModal()
                        finally:
                            dlg.Destroy()
                        self.NuovoButton.Enable(True)
                        return
                self.SorgenteText.SetValue('')
                self.DestinazioneText.SetValue('')
                self.NoteText.SetValue('')
                self.NomeText.SetEditable(True)
                self.SorgenteText.SetEditable(True)
                self.DestinazioneText.SetEditable(True)
                self.NoteText.SetEditable(True)
                self.SorgenteBroswer.Enable(True)
                self.FileEsclusiButton.Enable(True)
                self.MirrorRadioButton.Enable(True)
                self.UpDateRadioButton.Enable(True)
                self.AutomaticoRadiobutton.Enable(True)
                self.FlagCompresso.Enable(True)
                self.FlagDataOra.Enable(True)
                self.FlagHardLink.Enable(True)
                self.FlagMantieniPropietario.Enable(True)
                self.FlagPermessi.Enable(True)
                self.FlagSospeso.Enable(True)
                self.FlagRicorsivo.Enable(True)
                self.FlagCompleti.Enable(True)
                self.FileEsclusiButton.Enable(True)
                self.GraficView.InsertStringItem(self.index, str(result)) #trasformare in lower case
                self.index +=1
                self.NomeText.SetValue(str(result))
                self.SalvaButton.Enable(True)
            else:
                self.NuovoButton.Enable(True)
        finally:
            dlg.Destroy()
             

    def OnEliminaButtonButton(self, event):
        dlg = wx.MessageDialog(self, "Cancellare l'oggetto selezionato?", 'Warning', wx.CANCEL | wx.OK | wx.ICON_INFORMATION)
        try:
            result = dlg.ShowModal()
            if result == wx.ID_OK:
                self.GraficView.DeleteItem(self.Selected)
                self.SorgenteText.SetValue('')
                self.DestinazioneText.SetValue(' ')
                self.NomeText.SetValue(' ')
                self.NoteText.SetValue(' ')
                name = self.item
                self.indexRemoved.append(name)
                del(self.Sorgenti[name])
                del(self.Destinazioni[name])
                del(self.Note[name])
                del(self.Opzioni[name])
        finally:
            dlg.Destroy()

    def OnModificaButtonButton(self, event):
        if self.item != '':
            self.SorgenteText.SetEditable(True)
            self.DestinazioneText.SetEditable(True)
            self.NoteText.SetEditable(True)
            self.SorgenteBroswer.Enable(True)
            self.SalvaButton.Enable(True)
            self.FileEsclusiButton.Enable(True)
            self.MirrorRadioButton.Enable(True)
            self.UpDateRadioButton.Enable(True)
            self.AutomaticoRadiobutton.Enable(True)
            self.FileEsclusiButton.Enable(True)
            if self.AutomaticoRadiobutton.GetValue():
                self.FlagSospeso.Enable(True)
            else:
                self.FlagRicorsivo.Enable(True)
                self.FlagCompleti.Enable(True)
                self.FlagCompresso.Enable(True)
                self.FlagDataOra.Enable(True)
                self.FlagHardLink.Enable(True)
                self.FlagMantieniPropietario.Enable(True)
                self.FlagPermessi.Enable(True)
                self.FlagSospeso.Enable(True)
            
        else:
            dlg = wx.MessageDialog(self, 'Devi selezionare almeno un oggetto!', 'Attenzione', wx.OK | wx.ICON_INFORMATION)
            try:
                result = dlg.ShowModal()
            finally:
                dlg.Destroy()
                        
    def OnFileEsclusiButtonButton(self, event):
        files = []
        tmp = self.FileEsclusi[self.item]
        if len(tmp) > 0:
            files = tmp.split(',')
        dlg = FileEsclusiDialog(self, files)
        dlg.ShowModal()
        files = dlg.getValues()
        dlg.Destroy()

    def OnFlagMantieniPropietarioCheckbox(self, event):
        event.Skip()

    def OnAutomaticoRadiobuttonRadiobutton(self, event):
        self.FlagCompresso.Enable(False)
        self.FlagDataOra.Enable(False)
        self.FlagHardLink.Enable(False)
        self.FlagMantieniPropietario.Enable(False)
        self.FlagPermessi.Enable(False)
       # self.FlagSospeso.Enable(False)
        self.FlagRicorsivo.Enable(False)
        self.FlagCompleti.Enable(False)
    

    def OnMirrorRadioButtonRadiobutton(self, event):
        self.FlagCompresso.Enable(True)
        self.FlagDataOra.Enable(True)
        self.FlagHardLink.Enable(True)
        self.FlagMantieniPropietario.Enable(True)
        self.FlagPermessi.Enable(True)
        self.FlagSospeso.Enable(True)
        self.FlagRicorsivo.Enable(True)
        self.FlagCompleti.Enable(True)

    def OnUpDateRadioButtonRadiobutton(self, event):
        self.FlagCompresso.Enable(True)
        self.FlagDataOra.Enable(True)
        self.FlagHardLink.Enable(True)
        self.FlagMantieniPropietario.Enable(True)
        self.FlagPermessi.Enable(True)
        self.FlagSospeso.Enable(True)
        self.FlagRicorsivo.Enable(True)
        self.FlagCompleti.Enable(True)

    def OnPrefenzeButtonButton(self, event):
        dlg = GlobalOption(self, self.Client)
        dlg.ShowModal()
        self.Client = dlg.getValues()
        dlg.Destroy()

    def OnRipristinaBackupButtonButton(self, event):
        event.Skip()

    
